<%--
 *  File:    VisitProcessDetailEdit.jsp
 *  @Author: liangchen
 *  Date:    2009-10-10

 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.log4j.Category"%>
<%@ page import="com.oval.util.OvalLabel"%>
<%@ page import="com.oval.util.OvalCustomMessage"%>
<%@ page import="com.oval.util.OvalCustomColumn"%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval"%>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom"%>

<%
	  //init param
  String privilegeCode = "H0252";
  String strTableName = "";
  String strModuleName = "CRM";
  String contextPath = request.getContextPath();
%>
<%@ include file="/inc/Security.inc"%>
<%@ include file="/inc/PageDefault.inc"%>
<%@include file="/inc/Print.inc"%>
<%@ include file="/inc/FrmDefault.inc"%>


<iframe name="reloadHandler" style="display:none" ></iframe>
<html>
	<head>
		<title>VisitProcessDetailEdit</title>
		
		<PageFlow:CheckPageFlow pageName="p_visitprocessdetailedit" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css"
			type="text/css">
		<script language="JavaScript"
			src="../css/<%= strLanguageCode %>/script.js"></script>
		<script language="JavaScript" src="../js/FuncLib.js"></script>
		<script language="JavaScript" src="../js/ScriptLib.js"></script>
		<script language="JavaScript" src="../js/keyFunction.js"></script>
		<script language="JavaScript" src="../js/Calendar.js"></script>
		<script language="JavaScript" src="../js/SummaryDivision.js"></script>
		<script type="text/javascript" src="<%=contextPath %>/js/opal2/mootools.js"></script>
		<%@ include file="/inc/SummaryDivision.inc"%>
		
		<%
  HashMap userinfo = new HashMap();
  userinfo = (HashMap)session.getAttribute("userinfo");
  Integer orgid=new Integer(-1);
  String neworgid = null;
  if(userinfo.get("orgid")!=null)
  orgid = (Integer)userinfo.get("orgid");
  neworgid = orgid.toString();
    System.out.println("Trace \"isdefault\" ------- detail edit"+pageContext.getAttribute("isdefault"));
    String paraIsDefault = "";
  	String strIsDefault = null;
	if("Y".equals(((String)pageContext.getAttribute("isdefault")))) {
		strIsDefault = "&isdefault=Y";
		paraIsDefault = "Y";
	}else if ("N".equals(((String)pageContext.getAttribute("isdefault")))) {
		strIsDefault = "&isdefault=N";
		paraIsDefault = "N";
	}
		Vector actioninfo = (Vector)(pageContext.getAttribute("actioninfo"));
	%>
	<%
		HashMap newdetailinfo = null;
		if(pageContext.getAttribute("newdetailinfo") != null) { 
			newdetailinfo = (HashMap)(pageContext.getAttribute("newdetailinfo")); 
		}
	%>
	<%
		String isdetail = "";
		if("Y".equals(((String)pageContext.getAttribute("isdetail")))) {
			isdetail = "Y";
		}
		  String isNew = "";
		  if("Y".equals((String)pageContext.getAttribute("isNew"))) {
				isNew = "Y";
			}else if ("N".equals((String)pageContext.getAttribute("isNew"))) {
				isNew = "N";
			}
		    System.out.println("Trace \"isnew\" ------- detail edit"+isNew);
	%>
<script>
function page_summary(actionvalue,orderbyname){
	  var editform = summaryPrepare(actionsummaryform,actionvalue,orderbyname);
	  editform.action = "VisitProcessDetailEdit.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>";
	  editform.target = "_self";
	  isRunning = true;
	  editform.submit();  
}
function ensure() {
	  var editform = document.actionsummaryform;
	  editform.actionname.value = "move";
	  editform.target = "_self";
	  isRunning = true;
	  editform.submit();
	  cancel();
	}
	function page_getitem()
{
    document.actionsummaryform.visitprocessactionid.value='';
    document.actionsummaryform.actionname1.value='';
    document.actionsummaryform.description.value='';
    document.actionsummaryform.needfeedback.value='';
    
    if(isEmpty(document.actionsummaryform.actioncode.value))
    {
        return;
    }
    page_handleRequest('<%=contextPath%>',document.actionsummaryform);
}
function page_handleResponse()
{
   document.actionsummaryform.visitprocessactionid.value = getResponseData("visitprocessactionid");
   document.actionsummaryform.actionname1.value= getResponseData("actionname1");
   document.actionsummaryform.description.value = getResponseData("description");
   document.actionsummaryform.needfeedback.value = getResponseData("needfeedback");
   document.actionsummaryform.needsku.value= getResponseData("needsku");
   document.actionsummaryform.feedbacktype.value= getResponseData("feedbacktype");
   
  checkdisabled();
}
function page_getitem1(){
	var actioncode = document.actionsummaryform.actioncode.value;
	var datahandler = new  DataHandler();
	datahandler.add_params("actioncode" , actioncode , "string");
	datahandler.add_params("orgid","<%=orgid%>" , "integer");
	datahandler.getResult("visitprocessactionid","document.actionsummaryform.visitprocessactionid");
	datahandler.getResult("actionname1","document.actionsummaryform.actionname1");
	datahandler.getResult("description","document.actionsummaryform.description");
	datahandler.getResult("needfeedback","document.actionsummaryform.needfeedback");
	datahandler.getResult("needsku","document.actionsummaryform.needsku");
	datahandler.getResult("feedbacktype","document.actionsummaryform.feedbacktype");
	datahandler.add_job("j_getactioniteminfo");
	datahandler.runDataHandler();
	datahandler.add_function(checkdisabled());
}
var popwindow;
function page_selectaction()
{
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('ActionItemSelectPop.jsp?maxitem=12&languagecode=<%= strLanguageCode%>&<%= OvalTools.randomURL() %>','newwindow', 'height=400, width=850,top=150,left=300,toolbar=n0, menubar=no, scrollbars=auto, resizable=yes, location=no, status=no');
}

function page_setactionid(actionid,actioncode,actionname,description,needreq,needfeedback,valuename,needsku,needskugroup,feedbacktype)
{
  document.actionsummaryform.visitprocessactionid.value = actionid;
  document.actionsummaryform.actioncode.value = actioncode;
  document.actionsummaryform.actionname1.value = actionname;
  document.actionsummaryform.description.value = description;

  document.actionsummaryform.needfeedback.value = needfeedback;
  document.actionsummaryform.needsku.value = needsku;
  document.actionsummaryform.needskugroup.value = needskugroup; 
  document.actionsummaryform.needreq.value = needreq;
  document.actionsummaryform.valuename.value = valuename;
  document.actionsummaryform.feedbacktype.value = feedbacktype; 
  checkdisabled(needfeedback,needsku);
	
  if (popwindow != null)
    popwindow.close();
}
function checkdisabled() {
    var needreq = document.getElementsByName("needreq");
	var needfeedback = document.getElementsByName("needfeedback");
	var needsku = document.getElementsByName("needsku");
	var needskugroup = document.getElementsByName("needskugroup");
	
  if(needfeedback[0].value == "Y") {
  	document.actionsummaryform.needfeedback.checked = true;
  	if(needreq[0].value  == "Y") 	document.actionsummaryform.needreq.checked = true;
	else if(isEmpty(needreq.value)) document.actionsummaryform.needreq.checked = false;
	
	if(needsku[0].value  == "Y") 	document.actionsummaryform.needsku.checked = true;
	else if(isEmpty(needsku.value)) document.actionsummaryform.needsku.checked = false;
	
	if(needskugroup[0].value  == "Y") 	document.actionsummaryform.needskugroup.checked = true;
	else if(isEmpty(needskugroup.value)) document.actionsummaryform.needskugroup.checked = false;
  }
  else if (isEmpty(needfeedback[0].value )) {
    document.actionsummaryform.needfeedback.checked = false;
    document.actionsummaryform.needsku.checked = false;
    document.actionsummaryform.needskugroup.checked = false;
    document.actionsummaryform.needreq.checked = false;
  	document.actionsummaryform.feedbacktype.value = "-1";  
  }
}
function page_add(){

	if(isEmpty(actionsummaryform.stepno.value)) {
		alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_StepNumber",false)) %>");
		return;
	}
	if(!isNumber(actionsummaryform.stepno.value)) {
		alert("<%= message.getMessageDesc("VALUE_MUST_BE_NUMBER_TYPE",label.getLabelName("L_StepNumber",false)) %>");
		return;
	}
	if(isEmpty(actionsummaryform.actioncode.value)) {
		alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_actionguidecode",false)) %>");
		return;
	}
	if(isEmpty(actionsummaryform.actionname1.value)) {
		alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_actionguidename",false)) %>");
		return;
	}

 var frm = document.actionsummaryform;
   frm.actionname.value = "add";
   frm.target = "_self";
   isRunning = true;
   frm.submit();
}

function page_back()
{  
  parent.location.href = "VisitProcessSummary.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode%><%=JspHelper.filterNull( strIsDefault)%>";
}

function editModeText(obj,index,name,id) {
        if ($(name + index) == null) {
            var c = Trim(obj.innerText);
            var t = new Element('input', {
                'type':'text',
                'value':c,
                'styles':{
                        'width':'150px'
                         },
                'id':name + index,
                'name':name,
                'events':{
                    'blur':function() {
                        saveDataText(this,id,c);
                    },
                    'keydown':function() {
                        if (event.keyCode == 13) {
                            saveDataText(this,id,c);
                        }
                    }
                }
            });
           
            obj.innerHTML = '';
            t.inject(obj);
            selectText(t);
        }
    }
    
    function saveDataText(obj,id,c) {
        var p = obj.parentNode;
        if(Trim(obj.value) == ""){
          // alert("不能为空！");
           p.innerHTML =  "&nbsp;"+c;
           return;
        }
        if(parseFloat(obj.value) == parseFloat(c)){
           p.innerHTML = obj.value;
		   return;
        }
        p.innerHTML = obj.value;
        /*
        var req = new Request({
            'url':'<%=contextPath%>/Dispatcher',
            'method':'get',
            'data':'pagename=p_visitprocessdetailedit&actionname=usave&columnname=' + obj.name + '&columnvalue='+ encodeURI(obj.value) + '&visitprocessdetailid=' + id,
             onComplete:function(x){    //提交成功回调 
                  var data = eval("("+x+")");  
                  alert(data); 
             }
        });
        req.send(); 
        */
        //location.reload() ;
        document.actionsummaryform.columnname.value=obj.name;
        document.actionsummaryform.columnvalue.value=encodeURI(obj.value);
        document.actionsummaryform.processdetailid.value=id;
         var frm = document.actionsummaryform;
           frm.actionname.value = "usave";
           frm.target = "_self";
           isRunning = true;
           frm.submit();
    }

    function selectText(obj) {
        var range = obj.createTextRange();
        range.moveStart("character", 0);
        range.select();
    }
</script>
	</head>
	<%@ include file="/inc/CatchError.inc" %>
	<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

		<form name="actionsummaryform" method="post" action="<%=contextPath %>/Dispatcher">

			<input type="hidden" name="pagename" value="p_visitprocessdetailedit">
			<input type="hidden" name="actionname">   
            <input type="hidden" name="schema" value="v_actionsummary">
            <input type="hidden" name="qlname" value="selectbyactioncode">
			<input type="hidden" name="isdefault" value="<%= paraIsDefault %>">
			<input type="hidden" name="isNew" value="<%= isNew %>">	
			<input type="hidden" name="columnvalue">   
			<input type="hidden" name="columnname">   
			<input type="hidden" name="processdetailid">   	
			<table width="100%" cellspacing="0" cellpadding="0" border="0">

				<tr>
					<td>
						<table border="1" cellspacing="0" bordercolorlight="#999999"
							bordercolordark="#FFFFFF" cellpadding="0" width="100%">
							<tr>
								<td colspan="18" class="td_right">
									<a onclick='page_add()'><custom:button type="2"
											label="L_Add" imgsrc="add_btn.gif" border="0"
											style="width:60" />
									</a>
									<a onclick="page_delete()"><custom:button type="2"
											label="L_Delete" imgsrc="delete_btn.gif" border="0"
											style="width:60" />
									</a>
								</td>
							</tr>
							<tr class="deepblue-left">
								<td width="5%" class="title_center">
									&nbsp;
								</td>
								<td width="8%" class="title_center">
									<a href="javascript:page_summary('orderby','stepno')"><%= label.getLabelName("L_StepNumber") %></a>
								</td>
								<td width="15%" class="title_center">
									<a href="javascript:page_summary('orderby','actioncode')"><%= label.getLabelName("L_actionguidecode") %></a>
								</td>
								<td width="15%" class="title_center">
									<a href="javascript:page_summary('orderby','actionname1')"><%= label.getLabelName("L_actionguidename") %></a>
								</td>
								<td width="10%" class="title_center">
									<a href="javascript:page_summary('orderby','description1')"><%= label.getLabelName("L_Description") %></a>
								</td>
								<td width="8%" class="title_center">
									<a href="javascript:page_summary('orderby','needreq')"><%= label.getLabelName("L_Required") %></a>
								</td>
								<td width="8%" class="title_center">
									<a href="javascript:page_summary('orderby','needfeedback')"><%= label.getLabelName("L_needfeedback ") %></a>
								</td>
								<td width="8%" class="title_center">
									<a href="javascript:page_summary('orderby','needsku')"><%= label.getLabelName("L_IfNeedExpandBySKU") %></a>
								</td>
								<td width="12%" class="title_center">
									<a href="javascript:page_summary('orderby','needskugroup')"><%= label.getLabelName("L_skugroupopen") %></a>
								</td>
								<td width="12%" class="title_center">
									<a href="javascript:page_summary('orderby','valuename')"><%= label.getLabelName("L_FeedbackFormat") %></a>
								</td>
							</tr>

							<%
							int i=0; 
							Integer idx = new Integer(-1);
							%>
							<%
                        Vector totalsummary = (Vector) pageContext.getAttribute("visitprocessdetaileditinfo");
                        if (totalsummary == null)
                            totalsummary = new Vector();
                       Vector actionsourcecollection = (Vector) pageContext.getAttribute("actionsourcecollection");
                        if (actionsourcecollection == null)
                            actionsourcecollection = new Vector();
                            boolean bHasChecked = false;
                             String strClassType = new String("");
                            
               %>
							<logic:iterate id="visitprocessdetailinfo" collection="<%=totalsummary%>"
								indexId="orderid">
              
              <%
									            	HashMap tempMap = (HashMap)pageContext.getAttribute("visitprocessdetailinfo");
									            	if(i%2 == 1)
									            	{
									              		strClassType = "td-listrom";
									            	}else{
									              		strClassType = "";
									            	}
									            	i++;
									            	idx = new Integer(i-1);
									          	%>
								<tr onMouseOver="this.className='tr-over'"
									onMouseOut="this.className='<%=JspHelper.filterNull(strClassType)%>'"
									class="<%=JspHelper.filterNull( strClassType )%>">
									<td>
										<input type="checkbox" name="deleteids" value="<%=JspHelper.filterNull(tempMap.get("visitprocessdetailid") )%>" class="checkbox">
									</td>
									<td width="5%" onclick="editModeText(this,'<%=i%>','stepno','<custom:write name="visitprocessdetailinfo" property="visitprocessdetailid"/>');">
										<custom:write property="stepno" name="visitprocessdetailinfo" nbsp="true" />
									</td>
									<td>
										<custom:write property="actioncode" name="visitprocessdetailinfo"
											nbsp="true" />
									</td>
									<td>
										<custom:write property="actionname1" name="visitprocessdetailinfo"
											nbsp="true" />
									</td>
									<td>
										<custom:write property="description1" name="visitprocessdetailinfo"
											nbsp="true" />
									</td>
									<td class="title_center">
										<custom:write property="needreq" name="visitprocessdetailinfo"
											nbsp="true" />
									</td>
									<td class="title_center">
										<custom:write property="needfeedback" name="visitprocessdetailinfo"
											nbsp="true" />
									</td>
									<td class="title_center">
										<custom:write property="needsku" name="visitprocessdetailinfo" nbsp="true" />
									</td>
									<td class="title_center">
										<custom:write property="needskugroup" name="visitprocessdetailinfo" nbsp="true" />
									</td>
									<td class="title_center">
										<custom:write property="valuename" name="visitprocessdetailinfo"
											nbsp="true" />
									</td>
								</tr>
							</logic:iterate>
							
							
							<tr>
								<td>
									&nbsp;
								</td>
								<td>
									<custom:text name="newdetailinfo" property="stepno" size="10" />
									<font color="red"><%= label.getLabelName("L_Asterisk") %></font>
								</td>
								<td>
									<custom:text name="newdetailinfo" property="actioncode"
										size="12" onchange="page_getitem();" />
									<font color="red"><%= label.getLabelName("L_Asterisk") %></font><a onclick="page_selectaction()" ><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
								</td>
								<td>
									<custom:text name="newdetailinfo" property="actionname1"
										size="16" readonly="true" style="border:0"/>
								</td>
								<td>
									<custom:text name="newdetailinfo" property="description"
										size="40" readonly="true" style="border:0"/>
								</td>
							    <td class="title_center">
									<custom:checkbox styleClass="normalRadio" name="newdetailinfo" property="needreq" value="N" style="width:50" disabled="true" />
								</td>
								<td class="title_center">
									<custom:checkbox styleClass="normalRadio" name="newdetailinfo" property="needfeedback" value="N" style="width:20"
								 disabled="true" />
								</td>
								
								<td class="title_center">
									<custom:checkbox styleClass="normalRadio" name="newdetailinfo" property="needsku" value="N" style="width:50" disabled="true" />
								</td>
								<td class="title_center">
									<custom:checkbox styleClass="normalRadio" name="newdetailinfo" property="needskugroup" value="N" style="width:50" disabled="true" />
								</td>
								<td class="title_center">
									<custom:selectdic name="newdetailinfo" property="feedbacktype" dictType="FeedBackContentType" disabled="true" />
								</td>
							</tr>
							<%@ include file="/inc/SummaryAction.inc"%>
						</table>
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td class="summary_top"></td>
							</tr>
							<tr>
								<td class="td_center">
									<custom:hidden name="newdetailinfo"  property="valuename" />
									<%
										String visitprocessid = null;
										visitprocessid = (pageContext.getAttribute("visitprocessid")).toString(); 

										System.out.println("---"+visitprocessid+"---");
									%>
									<custom:hidden name="newdetailinfo"  property="visitprocessid" value="<%=visitprocessid%>" />
									<custom:hidden name="newdetailinfo"  property="visitprocessactionid" />	
									<input type="hidden" name="isdetail" value="<%= isdetail%>">				
									<a onclick="page_back();"><custom:button type="1"
											label="L_Back" imgsrc="new.gif" border="0" style="width:60" />
									</a>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			
		</form>
	</body>
	<script>

function page_delete(){
	if(nullChecked(document.actionsummaryform.deleteids,"<%=JspHelper.filterNull(totalsummary.size())%>"))
	  {
	    alert("<%= message.getMessageDesc("MUST_SELECT_ONE_RECORD") %>");
	    return;
	  }
	if ( ! confirm("<%= message.getMessageDesc("ARE_YOU_SURE")%>") ) 
	    return;
	    var frm = document.actionsummaryform;
	    frm.actionname.value = "deletesome";
		frm.target = "_self";
		isRunning = true;
		frm.submit();
	}
	</script>
</html>


